//
//  UIBarButtonItem+Extend.m
//  HJZWeiBo
//
//  Created by 蒋晨成 on 16/6/2.
//  Copyright © 2016年 蒋晨成. All rights reserved.
//

#import "UIBarButtonItem+Extend.h"
#import "UIImage+Extend.h"
@implementation UIBarButtonItem (Extend)


+(UIBarButtonItem *)itemWithImageName:(NSString *)ImageName highImageName:(NSString *)highImageName target:(id)target action:(SEL)action
 {
     //自定义UIView
     UIButton *btn=[[UIButton alloc]init];

     //设置按钮的背景图片（默认/高亮）
     [btn setBackgroundImage:[UIImage resizedImageWithName:ImageName] forState:UIControlStateNormal];
     [btn setBackgroundImage:[UIImage resizedImageWithName:highImageName] forState:UIControlStateHighlighted];

    //设置按钮的尺寸和图片一样大，使用了UIImage的分类
     CGRect newFrame = btn.frame;
     newFrame.size = btn.currentBackgroundImage.size;
     btn.frame = newFrame;
   
     [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];

     return [[UIBarButtonItem alloc]initWithCustomView:btn];
     
}



@end
